/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vinavac.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.vinavac.entity.util.EntityUtil;

/**
 *
 * @author Quang <quangtin3@gmail.com>
 */
@Entity
@Table(name = "staff")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Staff.findAll", query = "SELECT s FROM Staff s"),
    @NamedQuery(name = "Staff.findById", query = "SELECT s FROM Staff s WHERE s.id = :id"),
    @NamedQuery(name = "Staff.findByFullname", query = "SELECT s FROM Staff s WHERE s.fullname = :fullname"),
    @NamedQuery(name = "Staff.findByWorkplaceNumber", query = "SELECT s FROM Staff s WHERE s.workplaceNumber = :workplaceNumber"),
    @NamedQuery(name = "Staff.findByPhoneNumber", query = "SELECT s FROM Staff s WHERE s.phoneNumber = :phoneNumber"),
    @NamedQuery(name = "Staff.findByEmail", query = "SELECT s FROM Staff s WHERE s.email = :email"),
    @NamedQuery(name = "Staff.findByAddress", query = "SELECT s FROM Staff s WHERE s.address = :address"),
    @NamedQuery(name = "Staff.findByHomeNumber", query = "SELECT s FROM Staff s WHERE s.homeNumber = :homeNumber"),
    @NamedQuery(name = "Staff.findByPassword", query = "SELECT s FROM Staff s WHERE s.password = :password"),
    @NamedQuery(name = "Staff.findByLanguage", query = "SELECT s FROM Staff s WHERE s.language = :language"),
    @NamedQuery(name = "Staff.findByPermission", query = "SELECT s FROM Staff s WHERE s.permission = :permission")})
public class Staff implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 256)
    @Column(name = "FULLNAME")
    private String fullname;
    @Size(max = 256)
    @Column(name = "WORKPLACE_NUMBER")
    private String workplaceNumber;
    @Size(max = 256)
    @Column(name = "PHONE_NUMBER")
    private String phoneNumber;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 256)
    @Column(name = "EMAIL")
    private String email;
    @Size(max = 256)
    @Column(name = "ADDRESS")
    private String address;
    @Size(max = 256)
    @Column(name = "HOME_NUMBER")
    private String homeNumber;
    @Size(max = 256)
    @Column(name = "PASSWORD")
    private String password;
    @Size(max = 32)
    @Column(name = "LANGUAGE")
    private String language;
    @Size(max = 32)
    @Column(name = "PERMISSION")
    private String permission;
    @ManyToMany(mappedBy = "staffList")
    private List<WeeklyCalendar> weeklyCalendarList;
    @JoinColumn(name = "STAFF_ROLE", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private StaffRole staffRole;

    public Staff() {
    }

    public Staff(Integer id) {
        this.id = id;
    }

    public Staff(Integer id, String fullname) {
        this.id = id;
        this.fullname = fullname;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getWorkplaceNumber() {
        return workplaceNumber;
    }

    public void setWorkplaceNumber(String workplaceNumber) {
        this.workplaceNumber = workplaceNumber;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getHomeNumber() {
        return homeNumber;
    }

    public void setHomeNumber(String homeNumber) {
        this.homeNumber = homeNumber;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = EntityUtil.getPasswordHash(password);
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    @XmlTransient
    public List<WeeklyCalendar> getWeeklyCalendarList() {
        return weeklyCalendarList;
    }

    public void setWeeklyCalendarList(List<WeeklyCalendar> weeklyCalendarList) {
        this.weeklyCalendarList = weeklyCalendarList;
    }

    public StaffRole getStaffRole() {
        return staffRole;
    }

    public void setStaffRole(StaffRole staffRole) {
        this.staffRole = staffRole;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Staff)) {
            return false;
        }
        Staff other = (Staff) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getFullname() + " (" + getPhoneNumber() + "," + getEmail() + ")";
    }
}
